home *** CD-ROM | disk | FTP | other *** search
- ;; muttmode.mut : an electric Mutt mode
- ;; C Durland Public Domain
-
- (const
- Mutt-wrapper 75 ; column to wrap block comments at
-
- Mutt-start-comment ";; " ; what a comment usually starts with
-
- Enter-key-action "newline-and-indent"
- )
-
- (defun
- mutt-mode
- {
- (clear-modes)
-
- (bind-local-key Enter-key-action "^M")
- (bind-local-key "Mutt-mode-{" "{")
- (bind-local-key "Dr.Commento" "M-;")
- (bind-local-key "BS-untabify" "^H")
- (bind-local-key "format-Mutt-comment" "M-J")
- (bind-local-key "deref-key" "F-3")
- (bind-local-key "pgm-completer" "F-4")
-
- (major-mode "Mutt")
- }
- )
-
- (include me2.h)
- (include bs_untab.mut)
- (include block.mut)
-
- (defun
- deref-key ;; insert name of the function bound to a key
- {
- (string key bind)
- (key (ask "Key: "))
- (if (!= "" (bind (key-bound-to key)))(insert-text bind))
- }
- pgm-completer ; use command completion
- { (insert-text (complete 0x17 "command: ")) }
- "Mutt-mode-{" ; handle {
- {
- (int key n)
-
- (insert-text "{")(update)
- (switch (key (get-key))
- Space-bar
- (if (looking-at '\ *$') ; only ws til end of line
- { (insert-text " () }")(arg-prefix 3)(previous-character) }
- (insert-text " ")
- )
- Enter-key
- {
- (newline-and-indent)(n (+ 2 (current-column)))
- (if (looking-at '\ *$') ; white space to end of line
- {
- (insert-text "}")
- (beginning-of-line)(open-line)(to-col n)
- (insert-text "()")(previous-character)
- }
- (to-col n)
- )
- }
- default (exe-key key)
- )
- }
- )
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;; Comment Mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defun
- Dr.Commento ;; Start up a block comment
- {
- (int col)
-
- (col (current-column))(beginning-of-line)
- (if (looking-at '\ *$') ;; blank line => can start a block comment
- { (current-column col)(insert-text Mutt-start-comment) }
- {
- (if (looking-at '\ *;') ; "blanks ;" => can restart a block comment
- (current-column col)
- {
- ;; none of the above => bad place for a comment
- (current-column col)
- (msg "Not a valid place to start a block comment!")
- (done)
- })
- })
- ;; finish up turning on block comment mode
- (word-wrap Mutt-wrapper)
-
- (bind-local-key "Dr.Enter" "C-M")
- (bind-local-key "end-Mutt-comment" "M-;")
- (minor-mode "Dr. Commento")
- }
- end-Mutt-comment
- {
- (int col)
-
- ;; if [ws];[;...][ws] only thing on line, clear the line
- (col (current-column))
- (beginning-of-line)
- (if (looking-at '\ *;+\ *$') ; [ws];[;...][ws]$
- (cut-line)
- (current-column col))
-
- ;; turn off comment mode
- (minor-mode "")
- (word-wrap 0)
- (bind-local-key Enter-key-action "C-M")
- (bind-local-key "Dr.Commento" "M-;")
- }
- Dr.Enter ; handle Return
- {
- (int key)
-
- (open-line)(beginning-of-line)
- (if (looking-at '\(\ *;+\ *\)') ; [ws];[;...][ws]
- {
- (forward-line 1)
- (insert-text (get-matched '\1'))
- })
- }
- )
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;; Format block comment ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defun
- format-Mutt-comment
- {
- (int offset code-buffer-id scrbuf bag-id)
- (string semis)
-
- (code-buffer-id (current-buffer))
- (delete-region-as-block)
-
- (current-buffer (scrbuf (create-buffer scratch-buffer)))
- (clear-buffer)
- (insert-bag CUT-BUFFER)
-
- ; get the ;'s that start a comment
- (beginning-of-buffer)
- (semis
- (if (re-search-forward '^\ *\(;+\)') ; [ws];[;...]
- (get-matched '\1')
- ";;" ; if no ;'s, use my favorite
- ))
- ; Get the block offset from left margin
- ; Hopefully on same line as start comment
- (beginning-of-line)
- (while (is-space) (next-character))
- (offset (current-column))
-
- (beginning-of-buffer)
- (re-search-replace '^\ *;+' "") ; get rid of [white-space];[;...]
- (msg "Formatting comment ...")
- (beginning-of-buffer)
- (adjust-lines 10000 (- Mutt-wrapper (- offset 1) (length-of semis)) FALSE)
- (beginning-of-buffer)
-
- ; put ;'s in front of text
- (while (not (EoB))
- {
- (if (looking-at '^$')
- { (arg-prefix 1)(cut-line)(continue) } ; remove blank lines
- { (to-col offset)(insert-text semis) } ; else prepend ;
- )
- (forward-line 1)
- })
-
- ; replace comment
- (beginning-of-buffer)(set-mark)(end-of-buffer)
- (append-to-bag (bag-id (create-bag)) APPEND-REGION)
-
- (msg "Comment formatted.")
-
- (current-buffer code-buffer-id)
- (insert-bag bag-id)
-
- ; clean up
- (free-buffer scrbuf)(free-bag bag-id)
- }
- )
-